# encoding = utf-8
from pageObjects.LoginPage import LoginPage

class LoginAction(object):

    def __init__(self):
        print("Login......")

    @staticmethod
    def pwLogin(page, email, password):
        try:
            login = LoginPage(page)
            login.pwEmailObj().fill(email)
            login.passwordObj().fill(password)
            login.loginButtonObj().click()
        except Exception as err:
            raise err

if __name__ == "__main__":
    from playwright.sync_api import sync_playwright
    p = sync_playwright().start()
    url = "xxx"
    browser = p.chromium.launch(headless=False)
    # 创建 BrowserContext对象
    context = browser.new_context()
    # 启动跟踪功能
    # context.tracing.start(snapshots=True, sources=True, screenshots=True)

    page = context.new_page()
    page.goto(url)
    LoginAction().pwLogin(page, "xxx", "xxx")
    page.wait_for_timeout(10000)
    print("登录成功")